<?php

namespace app\agentapi\model;

use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\QuerySendDetailsRequest;
use app\common\library\WsgtLog;
class Sms{
    /**
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Dysmsapi
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([]);
        $config->accessKeyId = $accessKeyId;
        $config->accessKeySecret = $accessKeySecret;
        $config->endpoint = "dysmsapi.aliyuncs.com";
        return new Dysmsapi($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($phone,$name){
        $client = self::createClient('LTAI4FfcHwxThjTJ3BhUfasc', 'QU2CQ2GzRPcK1M8o8bUpcda3HzDkIJ');
        // 1.发送短信
        $sendReq = new SendSmsRequest([
            "phoneNumbers" =>$phone,
            "signName" => '房地产PLUS',
            "templateCode" => 'SMS_216276147',
            "templateParam" => "{\"name\":\"".$name."\"}"
        ]);
        //request.putQueryParameter("TemplateParam","{\"code\":\""+param+"\"}");
        $sendResp = $client->sendSms($sendReq);
        $code = $sendResp->body->code;
        $log = WsgtLog::instance();
        $log->setFilename('sms/duanxin');
        $log->info($phone, '接收的手机号');
        $log->info($name, '接收人姓名');
        $log->info($sendResp->body->code, '发送短信返回的code');
        $log->info($sendResp->body->message, '发送短信返回的message');
        if (!Utils::equalString($code, "OK")) {
            return $sendResp->body->message;
        }
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function codemain($phone,$code){
        $client = self::createClient('LTAI4FfcHwxThjTJ3BhUfasc', 'QU2CQ2GzRPcK1M8o8bUpcda3HzDkIJ');
        // 1.发送短信
        $sendReq = new SendSmsRequest([
            "phoneNumbers" =>$phone,
            "signName" => '房地产PLUS',
            "templateCode" => 'SMS_186480037',
            "templateParam" => "{\"code\":\"".$code."\"}"
        ]);
//request.putQueryParameter("TemplateParam","{\"code\":\""+param+"\"}");
        $sendResp = $client->sendSms($sendReq);
        $code = $sendResp->body->code;
        if (!Utils::equalString($code, "OK")) {
            return $sendResp->body->message;
        }else{
            return 1;
        }

    }


    public static function mainehuSms(){
        $client = self::createClient('LTAI4FfcHwxThjTJ3BhUfasc', 'QU2CQ2GzRPcK1M8o8bUpcda3HzDkIJ');
        // 1.发送短信
        $name="管理员";
        $sendReq = new SendSmsRequest([
            "phoneNumbers" =>'15109287068',
            "signName" => '房地产PLUS',
            "templateCode" => 'SMS_216276147',
            "templateParam" => "{\"name\":\"".$name."\"}"
        ]);
//request.putQueryParameter("TemplateParam","{\"code\":\""+param+"\"}");
        $sendResp = $client->sendSms($sendReq);
        $code = $sendResp->body->code;
        if (!Utils::equalString($code, "OK")) {
            return $sendResp->body->message;
        }

    }

}

